package cn.lixu._03oneWay;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.nio.charset.StandardCharsets;

/**
 * @author LiXu
 * @date 2022/08/18 0018 0:10:38
 */
public class Producter_1 {
    public static void main(String[] args) throws MQClientException, RemotingException, InterruptedException {
        //1.创建连接，获取对象
        DefaultMQProducer producer = new DefaultMQProducer("oneway_producter");
        //2.设置连接地址值
        producer.setNamesrvAddr("localhost:9876");
        //3.启动
        producer.start();
        //4.设置消息并发送
        Message message = new Message("hello_chengdu", "chengdu", "时间不在于你拥有多少，而在于你使用多少".getBytes(StandardCharsets.UTF_8));
        producer.sendOneway(message);
        //5.关闭连接
        producer.shutdown();
    }
}
